<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
    <h1 id="text1">a</h1>
  </body>

  <script>
      function color() {//获取随机颜色值
          r = Math.floor(Math.random() * 256);
          g = Math.floor(Math.random() * 256);
          b = Math.floor(Math.random() * 256);
          return "rgb(" + r + "," + g + "," + b + ")";
      }

      function RandomTest() {//设定文字样式
          document.getElementById("text1").style.color = color();
      }

      setInterval("RandomTest()", 300);
  </script>
</html>